<?php

namespace app\adminmall\controller;
use app\adminmall\model\CashmanageModel;
use app\common\controller\AdminBaseController;
use think\Db;
/**
 * 提现列表
 */
class CashmanageController extends AdminBaseController
{
 	 protected $model;
	
    protected function _initialize() {
        parent::_initialize();
        $this->model = new CashmanageModel();
    }
    /**
     * 提现列表
     * @author [longx] 
     */
    public function index( $page = 1){
    
        $list=$this->model
    	->table('long_member m,long_mall_cashmanage c')
    	->where('c.uid=m.id')
    	->paginate(10); 
        return $this->fetch('index', ['list' => $list]);
    }


    /**
     * 
     *添加
     * @author [longx] 
     */
    public function add()
    {
        if(request()->isAjax()){
        	$param=input('post.');
			if ($this->model->allowField(true)->save($param) !== false) {
                    $this->success('添加成功', url('Cashmanage/index'));
            } else {
                $this->error('添加失败');
            }
        }
        return $this->fetch();
    }


    /**
     * [edit 编辑]
     * @return [type] [description]
     * @author [longx]
     */
    public function edit($id)
    {
        if(request()->isAjax()){
            $param = input('post.');         
         	if ($this->model->allowField(true)->save($param,$id) !== false) {
                    $this->success('修改成功', url('Cashmanage/index'));
            } else {
                $this->error('修改失败');
            }
        }
        $id = input('param.id');
        $this->assign('ad',$this->model->find($id));
        return $this->fetch();
    }



    /**
     * [del删除]
     * @author [longx] 
     */
    public function delete()
    {
        $id = input('param.id');
        if ($this->model->destroy($id)) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }
    /**
     * [search查询]
     * @author [longx] 
     */
     public function search(){
    	$map = [];
    	$field = 'm.*,g.id,g.mobile,g.nick_name,g.city';
		if(request()->isPost()){
		 	$param = input('post.');
		 	
			if($param['nick_name']){
				$map['nick_name'] = ['like', '%'.$param['nick_name'].'%'];
			}
			//用户类型
			if($param['user_type']){
				$map['user_type'] = ['like', '%'.$param['user_type'].'%'];
			}
			//提现类型
			if($param['type'] != 0){
				$map['type'] = $param['type'];
			}
			//提现状态
			if($param['cash_status'] != 0){
				$map['cash_status'] = $param['cash_status'];
			}
			//提现账户
			if($param['message'] != 0){
				$map['message'] = $param['message'];
			}
			//状态
			if($param['cash_status']!=0 ){
				$map['cash_status'] = ['like', '%'.$param['cash_status'].'%'];
			}
			 //申请时间
			if($param['createtime']&&$param['end_time']){
				$map['m.createtime'] = ['between time', [$param['createtime'],$param['end_time']]];
			}
	    }	
    		$list=Db::name("mall_cashmanage")
    		->alias('m')
    		->join('__MEMBER__ g','g.id=m.uid')
    		->field($field)
    		->where($map)
    		->order("m.createtime desc")
    		->paginate(10);       
        return $this->fetch('index', ['list' => $list]);
    }
}